/**********************************************************************
 *@Project： CloudTest
 *@File: DictServiceImpl
 *@Date: 2017/3/3
 *@Copyright (C) 2013-2017 http://www.posun.cn. All Rights Reserved.
 ***********************************************************************
 *注意： 本内容仅限于深圳市普盛实业有限公司内部使用，禁止外泄
 **********************************************************************
 */
package com.posun.edu.system.impl;

import com.posun.cloud.tracing.TraceUtil;
import com.posun.edu.system.entity.Dict;
import com.posun.edu.system.repository.DictMapper;
import com.posun.edu.system.service.IDictService;
import com.posun.framework.base.impl.BaseServiceImpl;
import com.posun.framework.dto.DataSourceResult;
import com.posun.framework.orm.domain.Searchable;
import com.posun.framework.orm.toolkit.IdWorker;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * TODO<br>
 *
 * @author YL
 * @version 1.0
 * @createTime 2017/3/3 16:16
 * @ChangeLog
 */
@Service("dictService")
@CacheConfig(cacheNames = {"entityCache:dict"})
public class DictServiceImpl extends BaseServiceImpl<Dict, String> implements IDictService {

    @Resource
    private DictMapper dictMapper;

/*    @Resource
    private ITestService testService;

    @Resource
    private IOtherTestService otherTestService;*/

    @Cacheable(unless = "#result == null")
    public Dict findObject(String id) {
        return super.selectById(id);
    }

    @Override
    @Transactional
    @CachePut(key = "#dict.id")
    public Dict batchSave(Dict dict) {
        dict.setId(String.valueOf(IdWorker.getId()));
        dict.setDictName("MY TEST");
        super.insert(dict);
        return dict;
    }

    @Cacheable()
    @Override
    public List<Dict> findAll(Searchable<Dict> searchable) {
        Map<String, String> extMap = TraceUtil.getAttachments();
        System.out.println(extMap.get("empId"));
        System.out.println(extMap.get("user"));
        System.out.println(extMap.get("empName"));
        return super.selectList(searchable);
    }

    @Override
    @Cacheable()
    public DataSourceResult<Dict> selectResult(Searchable<Dict> searchable) {
        return super.selectDataSource(searchable);
    }
}
